<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" name="dateNow" id="dateNow"
                       th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}"/>
                <div class="select-list">
                    <ul>
                        <li>
                            订单ID：<input type="text" name="orderId"/>
                        </li>
                        <li>
                            交易商户：<input type="text" name="merchantName"/>
                        </li>
                        <li>
                            订单类型：
                            <select name="orderType" th:with="type=${@dict.getType('sys_new_order_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text"
                                   class="time-input" id="completeTimeStartTime1" placeholder="开始时间"
                                   name="params[completeTimeStartTime1]"/>
                            <span>-</span>
                            <input type="text"
                                   class="time-input" id="completeTimeEndTime1" placeholder="结束时间"
                                   name="params[completeTimeEndTime1]"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="search1()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                        <li>
                            <label class="text-warning" style="font-size:20px">交易笔数：<label id="number">0</label></label>
                            <label class="text-warning" style="font-size:18px">入账金额：<label
                                    id="totalEntryMoney">0</label></label>
                            <label class="text-warning" style="font-size:18px">分润金额：<label
                                    id="totalProfitMoney">0</label></label>
                            <label class="text-warning" style="font-size:18px">实际收入金额：<label
                                    id="totalMoney">0</label></label>

                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="system:companyMoneyChang:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    function search1() {
        if ($("#completeTimeStartTime1").val() == "" || $("#completeTimeEndTime1").val() == "") {
            $.modal.alertWarning("请选择创建时间")
        } else {
            var beginTime = $("#completeTimeStartTime1").val();
            var endTime = $("#completeTimeEndTime1").val();
            var d1 = new Date(beginTime);
            var d2 = new Date(endTime);
            if ((parseInt(d2 - d1) / (3600000 * 24)) > 31) {
                $.modal.alertWarning("时间间隔不能大于一个月")
            } else {
                $.table.search("formId");
            }
        }
    }

    //重置form
    function reset(formId) {

        var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
        $("#" + currentId)[0].reset();
        $("#completeTimeStartTime1").val($("#dateNow").val() + " 00:00:00")
        $("#completeTimeEndTime1").val($("#dateNow").val() + " 23:59:59")
    }

    $(function () {
        $("#completeTimeStartTime1").val($("#dateNow").val() + " 00:00:00")
        $("#completeTimeEndTime1").val($("#dateNow").val() + " 23:59:59")
    })
    var prefix = ctx + "system/companyMoneyChang";

    function queryParams(params) {
        return {
            "params[completeTimeStartTime1]": $("#completeTimeStartTime1").val(),
            "params[completeTimeEndTime1]": $("#completeTimeEndTime1").val(),
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            searchValue: params.search,
            orderByColumn: params.sort,
            isAsc: params.order
        };
    }

    var orderType = [[${@dict.getType('sys_new_order_type')}]];
    $(function () {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            modalName: "公司入账记录",
            queryParams: queryParams,
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: true,
                    formatter: function (value, row, index) {
                        if (row.number != null && row.totalMoney != null) {
                            $("#number").text(parseFormatNum(row.number, 0));
                            $("#totalEntryMoney").text(parseFormatNum(row.totalEntryMoney, 2))
                            $("#totalProfitMoney").text(parseFormatNum(row.totalProfitMoney, 2))
                            $("#totalMoney").text(parseFormatNum(row.totalMoney, 2))
                        }
                        return "";
                    }
                },
                {
                    field: 'entryMoney',
                    title: '入账金额',
                    align: 'center',
                },
                {
                    field: 'profitMoney',
                    title: '分润金额',
                    align: 'center',
                },
                {
                    field: 'money',
                    title: '实际收入金额',
                    align: 'center',
                },
                {
                    field: 'amountMoney',
                    title: '交易金额',
                    align: 'center',
                },
                {
                    field: 'orderId',
                    title: '订单ID',
                    align: 'center',
                },
                {
                    field: 'orderType',
                    title: '订单类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderType, value);
                    }
                },
                {
                    field: 'merchantName',
                    title: '交易商户',
                    align: 'center',
                },
                {
                    field: 'acqCode',
                    title: '通道编号',
                    align: 'center',
                },

                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                },
            ]
        };
        $.table.init(options);
    });

    function parseFormatNum(number, n) {

        if (n != 0) {
            n = (n > 0 && n <= 20) ? n : 2;
        }
        number = parseFloat((number + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
        var sub_val = number.split(".")[0].split("").reverse();
        var sub_xs = number.split(".")[1];
        var show_html = "";
        for (i = 0; i < sub_val.length; i++) {
            show_html += sub_val[i] + ((i + 1) % 3 == 0 && (i + 1) != sub_val.length ? "," : "");
        }
        if (n == 0) {
            return show_html.split("").reverse().join("");
        } else {
            return show_html.split("").reverse().join("") + "." + sub_xs;
        }
    }
</script>
</body>
</html>